//
//  CCAnimationHelper.m
//  NewYearRun
//
//  Created by Lion User on 11/01/2012.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "CCAnimationHelper.h"

@implementation CCAnimation (Helper)   
//直接索引图片名称   
//参数讲解：name：资源文件名  ；frameCount 总帧数   ；   delay ：每一帧的刷新时间
+(CCAnimation*) animationWithFile:(NSString*)name frameCount:(int)frameCount delay:(float)delay   
{   
    NSMutableArray* frames = [NSMutableArray arrayWithCapacity:frameCount];   
    NSString* file;   
    for (int i = 0; i < frameCount; i++)   
    {    
        file =nil;   
        file = [NSString stringWithFormat:@"%@%i.png", name, i];   
        CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];   
        CGSize texSize = texture.contentSize;   
        CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);   
        CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];   
        
        [frames addObject:frame];   
    }    
    return  [CCAnimation animationWithFrames:frames delay:delay];   
}   
//利用帧缓存中的帧名称
//参数讲解：frame：帧文件名  ；frameCount 总帧数   ；   delay ：每一帧的刷新时间
+(CCAnimation*) animationWithFrame:(NSString*)frame frameCount:(int)frameCount delay:(float)delay   
{   
    NSMutableArray* frames = [NSMutableArray arrayWithCapacity:frameCount];   
    NSString* file;   
    
    for (int i = 0; i <= frameCount; i++)   
    {   
        file =nil;   
        file = [NSString stringWithFormat:@"%@%i.png", frame, i];   
        CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];   
        CCSpriteFrame* frame = [frameCache spriteFrameByName:file];   
        [frames addObject:frame];   
    }   
    return  [CCAnimation animationWithFrames:frames delay:delay];   
}   
@end   
